{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "#--coding:utf-8 --\n",
    "#导入 numpy\n",
    "import numpy as np\n",
    "#导入opencv\n",
    "import cv2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "#打开图片文件\n",
    "img = cv2.imread('lenna.jpg')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "函数简介\n",
    "1、split—提取R、B、G分量(返回值顺序为：B、G、R)\n",
    "函数原型：split(m, mv=None)\n",
    "m：彩图矩阵\n",
    "mv：默认参数\n",
    "2、merge—合并R、G、B(参数顺序为：B、G、R)\n",
    "函数原型：merge(mv, dst=None)\n",
    "m：B、G、R分量\n",
    "mv：默认参数\n",
    "3、cvtColor—合并R、G、B(参数顺序为：B、G、R)\n",
    "函数原型：cvtColor(src, code, dst=None, dstCn=None)\n",
    "src：图像矩阵\n",
    "code：转化参数\n",
    "其他：默认参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#显示图片\n",
    "cv2.imshow(\"Hello opencv \", img)\n",
    "cv2.waitKey(0)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#R、G、B分量的提取\n",
    "(B,G,R) = cv2.split(img)\n",
    "#提取R、G、B分量\n",
    "cv2.imshow(\"Red\",R)\n",
    "cv2.imshow(\"Green\",G)\n",
    "cv2.imshow(\"Blue\",B)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#R、G、B的合并\n",
    "merged = cv2.merge([B,G,R])#合并R、G、B分量\n",
    "cv2.imshow(\"Merged\",merged)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
